
/**
 * @Project : Clion_ProgrammingExercises
 * @File : 2
 * @Author : WangRuoyu 
 * @Date : 2023/5/15 10:19
 */

#include "iostream"
#include "algorithm"

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    int nums[n];
    for (int i = 0; i < n; ++i) {
        nums[i] = 0;
    }

    int tmp = n;
    int p = -1;
    for (int i = 1;; ++i) {
        for (p++; p < p + n; ++p) {
            if (nums[p % n] != -1) {
                break;
            }
        }
        if (i % k == 0 || i % 10 == k) {
            nums[p % n] = -1;
            tmp--;
            if (tmp == 1) {
                break;
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        if (nums[i] != -1) {
            cout << i + 1;
            break;
        }
    }
    return 0;
}